package Commands;

/**
 *  Created with IntelliJ IDEA.
 *  Authors: Henrique ALberto Rusa and Danilo Barbosa Porto
 *  Date: 05/12/13
 *
 *  The TerminalCommand class implements the command interface, so it is a command used through out the application. This
 *  class codes the methods for the terminal class used on the terminal listeners of the application, close to the
 *  instructionPack class, realizing almost the same methods of verifying commands and getting data to process the
 *  terminal command.
 */
public class TerminalCommand implements Command{

    // Terminal String command written by the user
    private String []command;

    /*
     * Overriding the equals method to adjust it to our situation
     */
    @Override
    public boolean equals(Object anObject){
        return command[0] == anObject;
    }

    /*
     *  Constructor of the class, associating the line read from the terminal class to the terminal command, just to
     *  wrap the data to the terminal listener.
     */
    public TerminalCommand(String command){

        String []contentPeaces;
        contentPeaces =  command.split("\\s+");

        this.command = contentPeaces;
    }

    /*
     *  Method to identify if the terminal command is a list instruction returning a boolean to the caller.
     */
    public static boolean isListCommand(Command input){
        TerminalCommand t = (TerminalCommand)input;
        return t.getCommand(0).equals("ls");
    }

    /*
     *  Method to identify if the terminal command is a create file instruction returning a boolean to the caller.
     */
    public static boolean isCreateCommand(Command input){
        TerminalCommand t = (TerminalCommand)input;
        return t.getCommand(0).equals("create");
    }

    /*
     *  Method to identify if the terminal command is a remove file instruction returning a boolean to the caller.
     */
    public static boolean isRemoveCommand(Command input){
        TerminalCommand t = (TerminalCommand)input;
        return t.getCommand(0).equals("rm");
    }

    /*
     *  Method to identify if the terminal command is a read file instruction returning a boolean to the caller.
     */
    public static boolean isReadCommand(Command input){
        TerminalCommand t = (TerminalCommand)input;
        return t.getCommand(0).equals("open");
    }

    /*
     *  Method to identify if the terminal command is a write file instruction returning a boolean to the caller.
     */
    public static boolean isWriteCommand(Command input){
        TerminalCommand t = (TerminalCommand)input;
        return t.getCommand(0).equals("edit");
    }

    /*
     *  Method to identify if the terminal command is a clear terminal instruction returning a boolean to the caller.
     */
    public static boolean isClearCommand(Command input){
        TerminalCommand t = (TerminalCommand)input;
        return t.getCommand(0).equals("clear");
    }

    /*
     *  Method to identify if the terminal command is a cd terminal instruction returning a boolean to the caller.
     */
    public static boolean isCDCommand(Command input){
        TerminalCommand t = (TerminalCommand)input;
        return t.getCommand(0).equals("cd");
    }

    /*
     *  Method to identify if the terminal command is a mkdir terminal instruction returning a boolean to the caller.
     */
    public static boolean isMkdirCommand(Command input){
        TerminalCommand t = (TerminalCommand)input;
        return t.getCommand(0).equals("mkdir");
    }

    /*
     *  Method to identify if the terminal command is a mkdir terminal instruction returning a boolean to the caller.
     */
    public static boolean isRmdirCommand(Command input){
        TerminalCommand t = (TerminalCommand)input;
        return t.getCommand(0).equals("rmdir");
    }

    /*
     *  Method to identify if the terminal command is a enable terminal instruction returning a boolean to the caller.
     */
    public static boolean isEnableCommand(Command input){
        TerminalCommand t = (TerminalCommand)input;
        return t.getCommand(0).equals("enable");
    }

    /*
     *  Method to identify if the terminal command is a enable terminal instruction returning a boolean to the caller.
     */
    public static boolean isExitCommand(Command input){
        TerminalCommand t = (TerminalCommand)input;
        return t.getCommand(0).equals("exit");
    }

    /*
     *  Method to access all the data provided from the user String typed on the terminal.
     */
    public String getCommand(int index){
        return this.command[index];
    }

    /*
     *  Method to return the filename inside the terminal command instruction, returning a string of the name.
     */
    public String getFileName(){
        return this.command[1];
    }
}
